#ifndef _PARTICLE_H__
#define _PARTICLE_H__

#include <d3d9.h>
#include <d3dx9.h>
#include <vector>

using std::vector;

typedef struct
{
	float x;
	float y;
}Vector2D;

typedef struct{
	int r, g, b;
}Color;

class CParticle {	
protected: 	
	int			_num;	
	Vector2D	_vel;
	float		_angularVelocity;		// The speed that the angle is changing
	float		_size;					// The size of the particle
	int			_ttl;					// The 'time to live' of the particle
	bool		_isActive;
public: 
	float	_angle;						// The current angle of rotation of the particle
	Vector2D	_pos;
	int		_anpha;
	Color	_color;
	CParticle();
	void Init(	Vector2D pos, Vector2D vel,
		Color color, float size, float ttl);

	~CParticle();
	void Update();	
	bool IsAlive() {return _isActive;}
};

class CParticleEngine
{
private:
	Vector2D			_emitterPos;	//Location of emitter
	vector<CParticle>	_particles;		//Array of particles
	int					_numPar;		//Num of particle (Max)
	bool				_isActive;
	float				_time;
	long				_lastTime;
	int					_virtualPosX;

	LPDIRECT3DTEXTURE9	_Image;
	LPD3DXSPRITE		_SpriteHandler;	
public:
	CParticleEngine();
	CParticleEngine(LPD3DXSPRITE spriteHandler, Vector2D pos);
	~CParticleEngine();
	void Init(LPDIRECT3DTEXTURE9 image);
	void Update(int delta);
	void Render(int vituralLeft);
	void Add(CParticle par){ _particles.push_back(par);}
	void RemoveAt(int index);
	bool IsAlive(){return _isActive;}
	void GenarateNewParticle(int x, int y, int numPar);
};

#endif